//
//  NoItemsView.swift
//  TodoList
//
//  Created by 刘圣洁 on 2025/6/12.
//

import SwiftUI

struct NoItemsView: View {
    
    @State var animation: Bool = false
    let secondaryAccentColor: Color = Color("secondaryAccentColor")
    var body: some View {
        ScrollView {
            VStack(spacing: 10) {
                Text("没有事项！")
                    .font(.title)
                    .fontWeight(.semibold)
                Text("你是一个高效的人吗？我认为你应该点击添加按钮，在你的待办事项列表中添加一堆项目")
                    .padding(.bottom,20)
                NavigationLink {
                    AddView()
                } label: {
                    Text("添加事项")
                        .foregroundStyle(.white)
                        .font(.headline)
                        .frame(height: 55)
                        .frame(maxWidth: .infinity)
                        .background(animation ? secondaryAccentColor : .accentColor)
                        .clipShape(RoundedRectangle(cornerRadius: 10))
                }
                .padding(.horizontal, animation ? 30 : 50)
                .shadow(color: animation ? secondaryAccentColor.opacity(0.7) : .accentColor.opacity(0.7), radius: animation ? 30 : 10,x: 0,y: animation ? 50 : 30)
                .scaleEffect(animation ? 1.1 : 1.0)
                .offset(y: animation ? -7 : 0)
            }
            .frame(maxWidth: 400)
            .multilineTextAlignment(.center)
            .padding(40)
        .onAppear(perform: addAnimation)
        }
    }
    
    func addAnimation() {
        guard !animation else { return }
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
            withAnimation(
                Animation
                    .easeInOut(duration: 2.0)
                    .repeatForever()
            ) {
                animation.toggle()
            }
        }
    }
}

#Preview(traits: .sizeThatFitsLayout) {
    NoItemsView()
}
